package com.log.james.mapper;

import com.log.james.entity.DestIp;
import com.log.james.entity.EventsType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface EventsDao {
    /**
     *
     * @return
     */
    @Select("select e.starttime,e.endtime,e.srcip,e.description, a.name,a.advice from events e,attacktype a where e.type = a.id order by e.starttime desc")
    List<Map<String,Object>> getAttackEvents();

    /**
     * 攻击类型
     * @return
     */
    @Select("SELECT a.name as eventName,count(e.id) as num from `events` e,attacktype a WHERE e.type = a.id and e.starttime >= #{st} and e.endtime <= #{et} GROUP BY eventName ")
    List<Map<String,Object>> getAttackType(@Param("st")String st,@Param("et")String et);


    /**
     * 最新攻击事件
     * @return
     */
    @Select("SELECT e.starttime as time, a.`name` as type FROM attacktype a,`events` e where e.type = a.id and e.starttime >= #{st} and e.endtime <= #{et} group by type ORDER BY e.starttime ")
    List<Map<Object,Object>> getNewestEvent(@Param("st")Date st,@Param("et")Date et);

    /**
     * 攻击溯源
     * @return
     */

    @Select("SELECT e.srcip as destip,count(e.id) as num from events e where e.starttime >= #{st} and e.endtime <= #{et} GROUP BY e.srcip ORDER BY num DESC")
    List<DestIp> attackSource(@Param("st")Date st,@Param("et")Date et);

    @Select("select starttime,endtime from events where starttime >= #{st} and endtime <= #{et}")
    List<Map<String,Object>> getTodayEvents(@Param("st")Date st,@Param("et")Date et);

    @Select("select * from events where starttime = #{st}")
    List<Map<String,Object>> getEventsDetails(@Param("st")Date st);
}
